package com.ncucoder.server.service.impl;

import com.ncucoder.server.mapper.GoodsMapper;
import com.ncucoder.server.model.Goods;
import com.ncucoder.server.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author <a href="https://www.ncucoder.com">hsowan</a>
 * @since 2019-01-19 18:21
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int saveOrUpdate(Goods goods) {
        return goods.getId() != null ? goodsMapper.updateById(goods) : goodsMapper.save(goods);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public Goods getById(Long id) {
        return goodsMapper.getById(id);
    }
}
